/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.biz;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author puspa
 */
public class Perusahaan {

    public static ArrayList<Pekerja> DAFTAR_PEKERJA = new ArrayList<Pekerja>();

    public static void tambahPekerja(Pekerja pekerja) {
        DAFTAR_PEKERJA.add(pekerja);
    }

    public static void simpanFilePekerja(File file) {
        ObjectOutputStream outObject = null;
        try {
            FileOutputStream outStream = new FileOutputStream(file);
            outObject = new ObjectOutputStream(outStream);
            outObject.writeObject(DAFTAR_PEKERJA);
        } catch (IOException ex) {
            Logger.getLogger(Perusahaan.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            try {
                outObject.close();
            } catch (IOException ex) {
                Logger.getLogger(Perusahaan.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    public static void bacaFilePekerja(File file) {
        ObjectInputStream inObject = null;
        try {
            FileInputStream inStream = new FileInputStream(file);
            inObject = new ObjectInputStream(inStream);
            DAFTAR_PEKERJA = (ArrayList<Pekerja>)inObject.readObject();
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Perusahaan.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Perusahaan.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            try {
                inObject.close();
            } catch (IOException ex) {
                Logger.getLogger(Perusahaan.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}
